package com.briup.web;

import com.briup.pojo.Book;
import com.briup.utils.Result;

import com.briup.utils.ResultCode;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/books")
public class BookController {
    // 映射配置
    // 127.0.0.1:8081/books/getById/1
    // @RequestMapping(value = "/getById/{id}" ,method = RequestMethod.GET)
    // 简化配置
    // @GetMapping(value = "/getById/{id}")
    @GetMapping(value = "/{id}")
    public Result getById(@PathVariable Integer id){
        Book book = new Book();
        book.setId(id);
        book.setName("Java讲义");
        // 生成一个异常
        int n = id / 0;
        // 无统一标准的返回
        // return book;
        if(id == 1){
            return Result.failure(ResultCode.DATA_NONE);
        }
        return Result.success(book); 
        // {
        //     code:200,
        //     message:"success,书记查询成功",
        //     data:book,
        // }
    }

    // 127.0.0.1:8081/books/delById/1
    // @RequestMapping(value = "/delById/{id}" ,method = RequestMethod.GET)
    // 简化配置
    // @DeleteMapping(value = "/delById/{id}")
    @DeleteMapping(value = "/{id}")
    public Result delById(@PathVariable Integer id){
        System.out.println("delById"+id);
        // Book book = new Book();
        // book.setId(id);
        // book.setName("Java讲义");
        // return" book" + id + "删除成功";
        return Result.success();
        // {
        //     code:200,
        //     message:"success,书记删除成功",
        //     data:null,
        // }
    }
}